<?php
class QueHacemos extends Doctrine_Record {
    public function setTableDefinition() {
        $this->setTableName('que_hacemos');
        $this->hasColumn('titulo', 'string', 10000);
        $this->hasColumn('descripcion', 'string', 255);
        $this->hasColumn('title', 'string', 255);
        $this->hasColumn('description', 'string', 10000);
    }
    
    public function setUp(){
        $this->hasMany('Imagen as imagenes', array(
            'local' => 'id',
            'foreign' => 'id_que_hacemos'
        ));
    }
    
    //GETTERS Y SETTERS
    public function getTitulo () {
        return utf8_decode($this->_get('titulo'));
    }
    public function setTitulo ($q) {
        $this->_set('titulo', utf8_encode($q));
    }
    public function getTitle () {
        return utf8_decode($this->_get('title'));
    }
    public function setTitle ($q) {
        $this->_set('title', utf8_encode($q));
    }
    
    
    public function getDescripcion () {
        return utf8_decode($this->_get('descripcion'));
    }
    public function setDescripcion ($q) {
        $this->_set('descripcion', utf8_encode($q));
    }
    public function getDescription () {
        return utf8_decode($this->_get('description'));
    }
    public function setDescription ($q) {
        $this->_set('description', utf8_encode($q));
    }
    
    public function titulo ($idioma='es') {
        return ($idioma=='es')?$this->titulo:$this->title;
    }
    public function descripcion ($idioma='es') {
        return ($idioma=='es')?$this->descripcion:$this->description;
    }
    //FIN GETTERS Y SETTERS
    
    public static function getInstance () {
        return Doctrine::getTable('QueHacemos')->find(1);
    }
    
    public function imagenes () {
        $q = Doctrine_Query::create()
            ->select('i.*')
            ->from('Imagen i')
            ->innerJoin('i.queHacemos qh')
            ->where('qh.id = '.$this->id)
            ->orderBy('i.orden');
        return $q->execute();
    }
}
?>